package com.es.spring.aop.chain;

import com.es.spring.aop.common.TargetMethod;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @author 二十
 * @since 2021/11/9 9:27 下午
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public abstract class AbstractSlot {

    private AbstractSlot next;

    private TargetMethod targetMethod;


    public Object proceed(TargetMethod targetMethod)throws Exception{
        return null!=next?next.invoke(targetMethod):targetMethod.getMethod().invoke(targetMethod.getTarget(),targetMethod.getArgs());
    }

    abstract Object invoke(TargetMethod targetMethod);

    @Data
    public static class Head extends AbstractSlot{

        @Override
        Object invoke(TargetMethod targetMethod) {
            return null;
        }
    }
}
